﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Resources;
using System.IO;

namespace Cmic.Grammar.WP
{
    public partial class ContentPage : PhoneApplicationPage
    {
        public ContentPage()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            // get category id from Query String
            string subCategoryName;
            if (NavigationContext.QueryString.TryGetValue("subCategoryName", out subCategoryName))
            {
                //Category category = Category.GetCategoryById(subCategoryId);
                this.PageTitle.Text = subCategoryName;
            }

            string subCategoryId;
            if (NavigationContext.QueryString.TryGetValue("subCategoryId", out subCategoryId))
            {
                StreamReader sr = null;
                try
                {
                    StreamResourceInfo sRes = Application.GetResourceStream(new Uri(string.Format("Content/{0}.txt", subCategoryId), UriKind.Relative));
                    sr = new StreamReader(sRes.Stream, System.Text.Encoding.UTF8);
                    string strContent = sr.ReadToEnd();
                    this.txtContent.Text = strContent;
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (sr != null)
                    {
                        sr.Close();
                    }
                }
            }
        }
    }
}